FEATURETOOL = opp_featuretool
FEATURES_H = src/inet/features.h
SELFDOC = tests/fingerprint/SelfDoc

.PHONY: all clean cleanall neddoc makefiles makefiles-so makefiles-lib makefiles-exe checkenvir checkmakefiles doxy doc submodule-init

all: makefiles $(FEATURES_H)
	@cd src && $(MAKE)

clean: makefiles
	@cd src && $(MAKE) clean

cleanall: makefiles
	@cd src && $(MAKE) MODE=release clean
	@cd src && $(MAKE) MODE=debug clean
	@rm -f src/Makefile $(FEATURES_H) $(SELFDOC).xml

# extract makemake options from .oppbuildspec
# add -I. and -f at appropriate places to exactly match the makefile generated by the IDE
# note that the makemake options in .oppbuildspec are generated by the IDE and all --meta:xxx options must be thrown out
MAKEMAKE_OPTIONS := $(shell sed -n 's/.*makemake-options\s*=\s*"\([^"]*\)".*/\1/p' .oppbuildspec | sed 's/--meta:export-include-path/-I./g' | sed 's/--deep/-f --deep/g' | sed 's/ --meta:[^ ]*//g')
# add also options derived from enabled features
MAKEMAKE_OPTIONS := $(MAKEMAKE_OPTIONS) $(shell $(FEATURETOOL) options -f -l)

makefiles:
	@$(info *** CREATING Makefile with:)
	@$(info opp_makemake $(MAKEMAKE_OPTIONS))
	@cd src && opp_makemake $(MAKEMAKE_OPTIONS)

# generate an include file that contains all the WITH_FEATURE macros according to the current enablement of features
$(FEATURES_H): $(wildcard .oppfeaturestate) .oppfeatures
	@$(FEATURETOOL) defines >$(FEATURES_H).tmp
	@mv $(FEATURES_H).tmp $(FEATURES_H)

doc:
	@cd doc/src && $(MAKE)
	@doxygen doxy.cfg

ddoc:
	@cd doc/src && ./docker-make html && echo "===> file:$$(pwd)/_build/html/index.html"

$(SELFDOC).xml: $(SELFDOC).json
	@inet_selfdoc_json2xml <$< >$@

neddoc: $(SELFDOC).xml
	@opp_neddoc --verbose --no-automatic-hyperlinks -x "/*/examples,/*/tests,/*/showcases,/*/tutorials" -f $(SELFDOC).xml .

